//
//  MallHomeViewController.m
//  much
//
//  Created by weijunjie on 2019/1/4.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "MallHomeViewController.h"
#import "SearchHistoryViewController.h"
#import "UserLoginViewController.h"
#import "AffirmOrderViewController.h"


@interface MallHomeViewController()
@property (nonatomic, strong) UIView *searchView;
@end

@implementation MallHomeViewController
- (void)_reLayout {
    [self setupNavigationItems];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 隐藏导航条下黑线
    self.navigationView.lineView.backgroundColor = [UIColor clearColor];
}

- (void)setupNavigationItems {
    __weakConfigure
    [self.navigationView addCustomView:self.searchView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(__weakSelf.navigationView).offset(-15);
        make.left.equalTo(__weakSelf.navigationView).offset(15);
        make.bottom.equalTo(__weakSelf.navigationView).offset(-7);
        make.height.mas_equalTo(30);
    } callback:^(UIView *view) {
        SearchHistoryViewController *searchHistoryVC = [[SearchHistoryViewController alloc] init];
        [__weakSelf.navigationController pushViewController:searchHistoryVC animated:NO];
    }];
    
//    [self.navigationView addRightButtonWithTitle:@"登录" callback:^(UIView *view) {
//        [__weakSelf loginOut];
//    }];
}

//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    AffirmOrderViewController *vc = [[AffirmOrderViewController alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
//}

#pragma mark - 懒加载
- (UIView *)searchView {
    if (!_searchView) {
        _searchView = [[UIView alloc] init];
        _searchView.backgroundColor = Color244;
        _searchView.layer.cornerRadius = 15;
        NSString *title = @"搜索商品，低价好物任你选";
        CGFloat titleWidth = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : APPFONT(14)} context:nil].size.width;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = APPFONT(14);
        titleLabel.textColor = Color34;
        titleLabel.text = title;
        [_searchView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.searchView).offset((ScreenWidth - 30 - titleWidth - 24) * 0.5 + 24);
            make.top.bottom.equalTo(self.searchView);
        }];
        
        UIImageView *iconView = [[UIImageView alloc] init];
        iconView.image = [UIImage imageNamed:@"search_glass"];
        [_searchView addSubview:iconView];
        [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(titleLabel.mas_left).offset(-10);
            make.centerY.equalTo(titleLabel);
            make.width.height.mas_equalTo(14);
        }];
    }
    return _searchView;
}
@end
